// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   ESSDataStoreManager.java

package com.vandagroup.common.db;

import com.vandagroup.common.exp.ESSConnectionGetTimeOutException;
import java.sql.*;
import javax.sql.DataSource;

// Referenced classes of package com.vandagroup.common.db:
//            Globals, ServiceLocator

public class ESSDataStoreManager
{

    private static ESSDataStoreManager instance = null;

    private ESSDataStoreManager()
    {
    }

    public static synchronized ESSDataStoreManager getInstance()
    {
        if(instance == null)
            instance = new ESSDataStoreManager();
        return instance;
    }

    public Connection getConnection()
        throws SQLException, ESSConnectionGetTimeOutException
    {
        return getConnection("portal");
    }

    public Connection getConnection(String name)
        throws SQLException, ESSConnectionGetTimeOutException
    {
        Connection conn = null;
        if(Globals.getValue("portal.pooled").equals("true"))
            conn = ServiceLocator.getInstance().getDataSource(Globals.getValue("portal.dsname")).getConnection();
        else
            conn = DriverManager.getConnection(Globals.getValue("portal.url"), Globals.getValue("portal.user"), Globals.getValue("portal.password"));
        return conn;
    }

    public void freeConnection(Connection conn)
        throws SQLException
    {
        conn.close();
    }

    public void freeConnection(Connection conn, String dbName)
        throws SQLException
    {
        conn.close();
    }

    static 
    {
        try
        {
            Class.forName(Globals.getValue("drivers"));
        }
        catch(ClassNotFoundException e)
        {
            e.printStackTrace();
        }
    }
}
